//This is the GameLogon GUI object that represents a viewable panel representing logon controls
//This panel has the capability of using 2 states depending on which player is logging in (1 or 2)

//import only what we need to speed things up
import javax.swing.JPanel;
import javax.swing.JButton;
import javax.swing.JTextField;
import javax.swing.JPasswordField;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.KeyStroke;
import java.awt.GridBagLayout;
import java.awt.GridBagConstraints;
import java.awt.GridLayout;
import java.awt.Insets;
import java.awt.Dimension;
import java.awt.Color;
import java.awt.Graphics;
import java.io.File;
import java.io.IOException;
import javax.imageio.ImageIO;
import java.awt.Image;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import java.awt.event.KeyEvent;
import java.util.ArrayList;

public class GameLogon extends JPanel implements ActionListener {

	//declare class instance vars
	private Image background;
	private Image scaledbg;
	private Dimension prevsize;
	private JButton login_btn;
	private JButton clear_btn;
	private JButton newacc_btn;
	private JButton goback_btn;
	private JTextField username_fld;
	private JPasswordField password_fld;
	private JLabel instruct_lbl;
	private JLabel player_lbl;
	private int state;
	private String player1;
	private String player2;
	//common colors
	public static Color bgnorm = new Color(188, 143, 70);
	public static Color fgnorm = new Color(56, 5, 3);
	public static Color bgalt1 = new Color(221, 173, 98);
	public static Color fgalt1 = new Color(93, 15, 2);
	public static Color fgalt2 = new Color(242, 79, 1);

	//declare constants
	public static final int PLAYER1_LOGON = 0;
	public static final int PLAYER2_LOGON = 1;

	//our constructor
	public GameLogon() {

		//call our ancestor
		super();

		//build our layout with GridBag
		/*The following is taken directly from the Java 1.6 API specs.
			gridx - The initial gridx value.
				Specifies the cell containing the leading edge of the component's display area, where the first cell in a row has gridx=0.
				The leading edge of a component's display area is its left edge for a horizontal,
				left-to-right container and its right edge for a horizontal, right-to-left container.
				The value RELATIVE specifies that the component be placed immediately following the component that was added to the container
				just before this component was added.
				The default value is RELATIVE. gridx should be a non-negative value.
			gridy - The initial gridy value.
				Specifies the cell at the top of the component's display area, where the topmost cell has gridy=0.
				The value RELATIVE specifies that the component be placed just below the component that was added to the container
				just before this component was added.
				The default value is RELATIVE. gridy should be a non-negative value.
			gridwidth - The initial gridwidth value.
				Specifies the number of cells in a row for the component's display area.
				Use REMAINDER to specify that the component's display area will be from gridx to the last cell in the row.
				Use RELATIVE to specify that the component's display area will be from gridx to the next to the last one in its row.
				gridwidth should be non-negative and the default value is 1.
			gridheight - The initial gridheight value.
				Specifies the number of cells in a column for the component's display area.
				Use REMAINDER to specify that the component's display area will be from gridy to the last cell in the column.
				Use RELATIVE to specify that the component's display area will be from gridy to the next to the last one in its column.
				gridheight should be a non-negative value and the default value is 1.
			weightx - The initial weightx value.
				Specifies how to distribute extra horizontal space.
				The grid bag layout manager calculates the weight of a column to be the maximum weightx of all the components in a column.
				If the resulting layout is smaller horizontally than the area it needs to fill,
				the extra space is distributed to each column in proportion to its weight.
				A column that has a weight of zero receives no extra space.
				If all the weights are zero, all the extra space appears between the grids of the cell and the left and right edges.
				The default value of this field is 0. weightx should be a non-negative value.
			weighty - The initial weighty value.
				Specifies how to distribute extra vertical space.
				The grid bag layout manager calculates the weight of a row to be the maximum weighty of all the components in a row.
				If the resulting layout is smaller vertically than the area it needs to fill,
				the extra space is distributed to each row in proportion to its weight.
				A row that has a weight of zero receives no extra space.
				If all the weights are zero, all the extra space appears between the grids of the cell and the top and bottom edges.
				The default value of this field is 0. weighty should be a non-negative value.
			anchor - The initial anchor value.
				This field is used when the component is smaller than its display area.
				It determines where, within the display area, to place the component.
				There are three kinds of possible values: orientation relative, baseline relative and absolute.
				Orientation relative values are interpreted relative to the container's component orientation property,
				baseline relative values are interpreted relative to the baseline and absolute values are not.
				The absolute values are: CENTER, NORTH, NORTHEAST, EAST, SOUTHEAST, SOUTH, SOUTHWEST, WEST, and NORTHWEST.
				The orientation relative values are: PAGE_START, PAGE_END, LINE_START, LINE_END, FIRST_LINE_START,
				FIRST_LINE_END, LAST_LINE_START and LAST_LINE_END.
				The baseline relvative values are: BASELINE, BASELINE_LEADING, BASELINE_TRAILING, ABOVE_BASELINE,
				ABOVE_BASELINE_LEADING, ABOVE_BASELINE_TRAILING, BELOW_BASELINE, BELOW_BASELINE_LEADING, and BELOW_BASELINE_TRAILING.
				The default value is CENTER.
			fill - The initial fill value.
				This field is used when the component's display area is larger than the component's requested size.
				It determines whether to resize the component, and if so, how.
				The following values are valid for fill:
				* NONE: Do not resize the component.
				* HORIZONTAL: Make the component wide enough to fill its display area horizontally, but do not change its height.
				* VERTICAL: Make the component tall enough to fill its display area vertically, but do not change its width.
				* BOTH: Make the component fill its display area entirely.
				The default value is NONE.
			insets - The initial insets value.
				This field specifies the external padding of the component,
				the minimum amount of space between the component and the edges of its display area.
				The default value is new Insets(0, 0, 0, 0).
			ipadx - The initial ipadx value.
				This field specifies the internal padding of the component, how much space to add to the minimum width of the component.
				The width of the component is at least its minimum width plus ipadx pixels.
				The default value is 0.
			ipady - The initial ipady value.
				This field specifies the internal padding, that is, how much space to add to the minimum height of the component.
				The height of the component is at least its minimum height plus ipady pixels.
				The default value is 0.
		*/
		//assuming an invisible grid of 12 x 12

		this.setLayout(new GridBagLayout());
		//add a filler panel to fill the entire first 2 columns (1st-12th row) (1st-2nd column)
		JPanel temppan1 = new JPanel();
		temppan1.setOpaque(false);
		temppan1.setVisible(true);
		this.add(temppan1, new GridBagConstraints( 0, 0, 2, 8, 1, 1,
			GridBagConstraints.CENTER, GridBagConstraints.BOTH, new Insets(0,0,0,0),
			0, 0));
		//add our instruction label
		//we want this to be at the top along the middle (1st row) (3rd-11th column)
		this.instruct_lbl = new JLabel("Instructions");
		this.instruct_lbl.setBackground(GameLogon.bgnorm);
		this.instruct_lbl.setForeground(GameLogon.fgnorm);
		this.instruct_lbl.setOpaque(true);
		this.add(this.instruct_lbl, new GridBagConstraints( 2, 0, 8, 1, 1, 1,
			GridBagConstraints.NORTH, GridBagConstraints.HORIZONTAL, new Insets(3,0,3,0),
			0, 0));
		//add a filler panel to fill the lower 3rd column (2nd-9th row)
		JPanel temppan2 = new JPanel();
		temppan2.setOpaque(false);
		temppan2.setVisible(true);
		this.add(temppan2, new GridBagConstraints( 2, 1, 1, 7, 1, 1,
			GridBagConstraints.CENTER, GridBagConstraints.BOTH, new Insets(0,0,0,0),
			0, 0));
		//add a filler panel to fill the right side (2nd-4th row) (4th-12th column)
		JPanel temppan3 = new JPanel();
		temppan3.setOpaque(false);
		this.add(temppan3, new GridBagConstraints( 3, 1, 9, 3, 1, 1,
			GridBagConstraints.CENTER, GridBagConstraints.VERTICAL, new Insets(0,0,0,0),
			0, 0));
		//add our player label
		//we want this to be at the center below the text of the background (5th row) along the middle (6th column)
		this.player_lbl = new JLabel("Player");
		this.player_lbl.setBackground(GameLogon.bgnorm);
		this.player_lbl.setForeground(GameLogon.fgnorm);
		this.player_lbl.setOpaque(true);
		this.add(this.player_lbl, new GridBagConstraints( 5, 4, 2, 1, 1, 0.2,
			GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(0,0,0,0),
			0, 0));
		//add our username label
		//we want this to be at the center below the text of the background (6th row) along the middle (5th column)
		JLabel username_lbl = new JLabel("username:");
		username_lbl.setBackground(GameLogon.bgnorm);
		username_lbl.setForeground(GameLogon.fgnorm);
		username_lbl.setOpaque(true);
		this.add(username_lbl, new GridBagConstraints( 4, 5, 1, 1, 1, 0.2,
			GridBagConstraints.EAST, GridBagConstraints.NONE, new Insets(0,0,0,0),
			0, 0));
		//add our password label
		//we want this to be at the center below the text of the background (7th row) along the middle (5th column)
		JLabel password_lbl = new JLabel("password:");
		password_lbl.setBackground(GameLogon.bgnorm);
		password_lbl.setForeground(GameLogon.fgnorm);
		password_lbl.setOpaque(true);
		this.add(password_lbl, new GridBagConstraints( 4, 6, 1, 1, 1, 0.2,
			GridBagConstraints.EAST, GridBagConstraints.NONE, new Insets(0,0,0,0),
			0, 0));
		//add our username field
		//we want this to be at the center below the text of the background (6th row) along the middle (6th-8th column)
		this.username_fld = new JTextField(15);
		//this.username_fld.setBackground(GameLogon.bgnorm);
		//username_fld.setForeground(GameLogon.fgnorm);
		//add action listener to handler ENTER key presses as login attempts
		this.username_fld.addActionListener(this);
		this.add(this.username_fld, new GridBagConstraints( 5, 5, 3, 1, 1, 0.2,
			GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, new Insets(0,0,0,0),
			0, 0));
		//add our password field
		//we want this to be at the center below the text of the background (7th row) along the middle (6th-8th column)
		this.password_fld = new JPasswordField(15);
		//this.password_fld.setBackground(GameLogon.bgnorm);
		//password_fld.setForeground(GameLogon.fgnorm);
		//add action listener to handler ENTER key presses as login attempts
		this.password_fld.addActionListener(this);
		this.add(this.password_fld, new GridBagConstraints( 5, 6, 3, 1, 1, 0.2,
			GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, new Insets(0,0,0,0),
			0, 0));
		//add our login button
		//we want this to be on the left under the entry fields (8th row) (5th-6th column)
		this.login_btn = new JButton("Login");
		this.login_btn.setBackground(GameLogon.bgnorm);
		this.login_btn.setForeground(GameLogon.fgnorm);
		this.login_btn.addActionListener(this);
		/*
		//give this button a special input mapping
		// to fire when the ENTER key is pressed while the window is in focus
			this.login_btn.getInputMap(JButton.WHEN_IN_FOCUSED_WINDOW).put(
				KeyStroke.getKeyStroke(KeyEvent.VK_ENTER, 0, true), new Object());
		*/
		//scratch that
		this.add(this.login_btn, new GridBagConstraints( 4, 7, 2, 1, 1, 0.3,
			GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL, new Insets(0,0,0,0),
			0, 0));
		//add our clear button
		//we want this to be on the right under the entry fields (8th row) (7th-8th column)
		this.clear_btn = new JButton("Clear");
		this.clear_btn.setBackground(GameLogon.bgnorm);
		this.clear_btn.setForeground(GameLogon.fgnorm);
		this.clear_btn.addActionListener(this);
		this.add(this.clear_btn, new GridBagConstraints( 6, 7, 2, 1, 1, 0.3,
			GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL, new Insets(0,0,0,0),
			0, 0));
		//add our new-account button
		//we want this to be on the far right under the entry fields (8th row) (9th-10th column)
		this.newacc_btn = new JButton("New Account");
		this.newacc_btn.setBackground(GameLogon.bgnorm);
		this.newacc_btn.setForeground(GameLogon.fgnorm);
		this.newacc_btn.addActionListener(this);
		this.add(this.newacc_btn, new GridBagConstraints( 8, 7, 2, 1, 1, 0.3,
			GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL, new Insets(0,0,0,0),
			0, 0));
		//add a filler panel to fill the leftover (9th-11th row) (4th-12th column)
		JPanel temppan4 = new JPanel();
		temppan4.setOpaque(false);
		this.add(temppan4, new GridBagConstraints( 3, 8, 9, 2, 1, 1,
			GridBagConstraints.CENTER, GridBagConstraints.BOTH, new Insets(0,0,0,0),
			0, 0));
		//add our go back button
		//we want this to be at the bottom right corner (12th row) (11th column)
		this.goback_btn = new JButton("Go Back");
		this.goback_btn.setBackground(GameLogon.bgnorm);
		this.goback_btn.setForeground(GameLogon.fgnorm);
		this.goback_btn.addActionListener(this);
		this.add(this.goback_btn, new GridBagConstraints( 10, 11, 2, 1, 1, 0.3,
			GridBagConstraints.EAST, GridBagConstraints.VERTICAL, new Insets(0,0,0,0),
			0, 0));

		/*
		//this is the simple layering of GridLayouts version
		//we will initially need to have 3 vertical grids
		this.setLayout(new GridLayout(1,3));
		//our top grid will only consist of the instruction label
		JPanel tp1 = new JPanel();
		//split the top grid into another 4 vertical grids
		tp1.setLayout(new GridLayout(1,4));
			//setup instruction label
			this.instruct_lbl = new JLabel("Instructions");
			this.instruct_lbl.setBackground(GameLogon.bgnorm);
			this.instruct_lbl.setForeground(GameLogon.fgnorm);
			//setup fillers
			JPanel tp2 = new JPanel();
			tp2.setOpaque(false);
			JPanel tp3 = new JPanel();
			tp3.setOpaque(false);
			JPanel tp4 = new JPanel();
			tp4.setOpaque(false);
			//add
			tp1.add(instruct_lbl);
			tp1.add(tp2);
			tp1.add(tp3);
			tp1.add(tp4);
			tp1.setOpaque(true);
			tp1.setVisible(true);
		//our middle grid will contain the majority of components
		JPanel tp12 = new JPanel();
		//split the middle grid into another 4 vertical grids
		tp12.setLayout(new GridLayout(1,4));
			//this first grid is where we put the player label
			JPanel tp13 = new JPanel();
			//split it into 3 horizontal sub grids
			tp13.setLayout(new GridLayout(3,1));
				//setup filler for first grid
				JPanel tp14 = new JPanel();
				tp14.setOpaque(false);
				//setup player label
				this.player_lbl = new JLabel("Player");
				this.player_lbl.setBackground(GameLogon.bgnorm);
				this.player_lbl.setForeground(GameLogon.fgnorm);
				//setup filler for last grid
				JPanel tp15 = new JPanel();
				tp15.setOpaque(false);
				//add
				tp13.add(tp14);
				tp13.add(this.player_lbl);
				tp13.add(tp15);
				tp13.setOpaque(true);
				tp13.setVisible(true);
			//this second grid is where we put the username label and field
			JPanel tp16 = new JPanel();
			//split it into 2 horizontal sub grids
			tp16.setLayout(new GridLayout(2,1));
				//setup our left subgrid
				JPanel tp17 = new JPanel();
				//split this into 3 horizontal grids
				tp17.setLayout(new GridLayout(3,1));
					//setup fillers
					JPanel tp18 = new JPanel();
					tp18.setOpaque(false);
					JPanel tp19 = new JPanel();
					tp19.setOpaque(false);
					//setup username label
					JLabel username_lbl = new JLabel("username:");
					username_lbl.setBackground(GameLogon.bgnorm);
					username_lbl.setForeground(GameLogon.fgnorm);
					//add
					tp17.add(tp18);
					tp17.add(tp19);
					tp17.add(username_lbl);
					tp17.setOpaque(true);
					tp17.setVisible(true);
				//setup our right subgrid
				JPanel tp20 = new JPanel();
				//split this into 2 horizontal grids
				tp20.setLayout(new GridLayout(2,1));
					//setup username field
					this.username_fld = new JTextField(15);
					this.username_fld.setBackground(GameLogon.bgnorm);
					//setup filler
					JPanel tp21 = new JPanel();
					tp21.setOpaque(false);
					//add
					tp20.add(this.username_fld);
					tp20.add(tp21);
					tp20.setOpaque(true);
					tp20.setVisible(true);
				//add
				tp16.add(tp17);
				tp16.add(tp20);
				tp16.setOpaque(true);
				tp16.setVisible(true);
			//this third grid is where we put the username label and field
			JPanel tp22 = new JPanel();
			//split it into 2 horizontal sub grids
			tp22.setLayout(new GridLayout(2,1));
				//setup our left subgrid
				JPanel tp23 = new JPanel();
				//split this into 3 horizontal grids
				tp23.setLayout(new GridLayout(3,1));
					//setup fillers
					JPanel tp24 = new JPanel();
					tp24.setOpaque(false);
					JPanel tp25 = new JPanel();
					tp25.setOpaque(false);
					//setup password label
					JLabel password_lbl = new JLabel("password:");
					password_lbl.setBackground(GameLogon.bgnorm);
					password_lbl.setForeground(GameLogon.fgnorm);
					//add
					tp23.add(tp24);
					tp23.add(tp25);
					tp23.add(password_lbl);
					tp23.setOpaque(true);
					tp23.setVisible(true);
				//setup our right subgrid
				JPanel tp26 = new JPanel();
				//split this into 2 horizontal grids
				tp26.setLayout(new GridLayout(2,1));
					//setup password field
					this.password_fld = new JPasswordField(15);
					this.password_fld.setBackground(GameLogon.bgnorm);
					//setup filler
					JPanel tp27 = new JPanel();
					tp27.setOpaque(false);
					//add
					tp26.add(this.password_fld);
					tp26.add(tp27);
					tp26.setOpaque(true);
					tp26.setVisible(true);
				//add
				tp22.add(tp23);
				tp22.add(tp26);
				tp22.setOpaque(true);
				tp22.setVisible(true);
			//this fourth grid is where we put the login, clear, and new-account buttons
			JPanel tp28 = new JPanel();
			//split it into 3 horizontal sub grids
			tp28.setLayout(new GridLayout(3,1));
				//setup left grid filler
				JPanel tp29 = new JPanel();
				tp29.setOpaque(false);
				//setup button grid
				JPanel tp30 = new JPanel();
				//split this into 3 horizontal grids for the 3 buttons
				tp30.setLayout(new GridLayout(3,1));
					//setup our login button
					this.login_btn = new JButton("Login");
					this.login_btn.setBackground(GameLogon.bgnorm);
					this.login_btn.setForeground(GameLogon.fgnorm);
					this.login_btn.addActionListener(this);
					//setup our clear button
					this.clear_btn = new JButton("Clear");
					this.clear_btn.setBackground(GameLogon.bgnorm);
					this.clear_btn.setForeground(GameLogon.fgnorm);
					this.clear_btn.addActionListener(this);
					//setup our new-account button
					this.newacc_btn = new JButton("New Account");
					this.newacc_btn.setBackground(GameLogon.bgnorm);
					this.newacc_btn.setForeground(GameLogon.fgnorm);
					this.newacc_btn.addActionListener(this);
					//add
					tp30.add(this.login_btn);
					tp30.add(this.clear_btn);
					tp30.add(this.newacc_btn);
					tp30.setOpaque(true);
					tp30.setVisible(true);
				//setup right grid filler
				JPanel tp31 = new JPanel();
				tp31.setOpaque(false);
				//add
				tp28.add(tp29);
				tp28.add(tp30);
				tp28.add(tp31);
				tp28.setOpaque(true);
				tp28.setVisible(true);
		//our bottom grid will only consist of the go back button
		JPanel tp5 = new JPanel();
		//split the bottom grid into another 3 vertical grids
		tp5.setLayout(new GridLayout(1,3));
			//setup fillers
			JPanel tp6 = new JPanel();
			tp6.setOpaque(false);
			JPanel tp7 = new JPanel();
			tp7.setOpaque(false);
			//setup bottom container
			JPanel tp8 = new JPanel();
			tp8.setLayout(new GridLayout(4,1));
			//our furthest bottom grid should be split into 4 horizontal grids
				//setup fillers
				JPanel tp9 = new JPanel();
				tp9.setOpaque(false);
				JPanel tp10 = new JPanel();
				tp10.setOpaque(false);
				JPanel tp11 = new JPanel();
				tp11.setOpaque(false);
				//setup go back button
				this.goback_btn = new JButton("Go Back");
				this.goback_btn.setBackground(GameLogon.bgnorm);
				this.goback_btn.setForeground(GameLogon.fgnorm);
				this.goback_btn.addActionListener(this);
				//add
				tp8.add(tp9);
				tp8.add(tp10);
				tp8.add(tp11);
				tp8.add(this.goback_btn);
				tp8.setOpaque(true);
				tp8.setVisible(true);
			//add
			tp5.add(tp6);
			tp5.add(tp7);
			tp5.add(tp8);
			tp5.setOpaque(true);
			tp5.setVisible(true);
		//add the main grids
		this.add(tp1);
		this.add(tp12);
		this.add(tp5);
		*/


		//set a reasonable size to match the ratio of our splash image
		this.setPreferredSize(new Dimension(500, 375));

		//try to get our splash image
		//if we cannot retrieve the image, it is somewhat serious
		//but I don't know what we could do from that point on :(
		try{
			background = ImageIO.read(new File("images\\SplashMedium.jpg"));
		}catch (IOException EXC){
			//this likely means there was some problem accessing the image file
		}catch (IllegalArgumentException EXC){
			//this likely means that for some reason we couldn't create the File object
		}

		//setup our state
		this.setupP1Logon();

		//setup visibilities
		this.setVisible(true);
		this.setOpaque(true);

	}

	//override this so that we can customize drawing of the component
	//specifically so that we always have our pretty splash screen behind us :D
	public void paintComponent(Graphics g) {
		
		//call our ancestor
		super.paintComponent(g);
		
		System.out.println("$1GameLogon: painting...");
		
		//getSize is a retarded method, as such it requires
		//  we pass a Dimension object that it will use by referrence to store the size
		//the retarded part is that it also returns the same Dimension object
		//  go figure...
		Dimension panelsize = new Dimension(0,0);
		this.getSize(panelsize);
		
		//check if previous size has been declared yet
		if (this.prevsize == null){
			this.prevsize = new Dimension(panelsize);
		}
		
		//check if we need to rescale the image
		// this can occur if the component size changed
		// or it can occur if the image has not been scaled yet
		if (this.scaledbg == null || !panelsize.equals(this.prevsize)){
			this.scaledbg = background.getScaledInstance(panelsize.width,
			panelsize.height, Image.SCALE_SMOOTH);
		}
		g.drawImage(scaledbg, 0, 0, null);
		
		//reset the previous scale size
		this.prevsize = new Dimension(panelsize);
		
	}

	//convenience method for setting up parameters for player 1 logon
	public void setupP1Logon() {

		state = GameLogon.PLAYER1_LOGON;
		instruct_lbl.setText("First player, login or create a new account to play the game.");
		player_lbl.setText("Player 1 Logon");
		//gain focus
		this.username_fld.requestFocus();
		//draw what we have changed
		this.repaint();

	}

	//convenience method for setting up parameters for player 2 logon
	public void setupP2Logon() {

		state = GameLogon.PLAYER2_LOGON;
		instruct_lbl.setText("Second player, login or create a new account to play the game.");
		player_lbl.setText("Player 2 Logon");
		//gain focus
		this.username_fld.requestFocus();
		//draw what we have changed
		this.repaint();

	}

	//hidden convenience method for showing the user an information notice
	private void showInfoNotice(String info, String title) {

		this.repaint();
		JOptionPane.showMessageDialog(this, info, title, JOptionPane.INFORMATION_MESSAGE);

	}

	//hidden convenience method for clearing out user name and password info
	private void clearFields() {

		this.username_fld.setText("");
		this.password_fld.setText("");

	}

	//hidden convenience method for attempting to log in
	private void loginPlayer() {

		//declare some vars
		String curruser = this.username_fld.getText();
		String currpass = new String(this.password_fld.getPassword());
		boolean result = false;

		result = UIController.authenticateUser(curruser, currpass);
		if (!result){
			this.showInfoNotice("The account could not be authenticated!"
				+ "\nThe password is incorrect or the account does not exist."
				+ "\n\nMake sure CAPSLOCK is off."
				+ "\nClick the \"New Account\" button to create an account.", "Authentication Failure");
		}else{
			this.clearFields();
			if (this.state == GameLogon.PLAYER2_LOGON){
				this.player2 = new String(curruser);
				if (this.player2.equals(this.player1)){
					//this.showInfoNotice("Player 2 must sign on with a different account than Player 1!", "Duplicate Player Login");
					UIController.printPopup("Player 2 cannot use the same account as Player 1!", 10.5);
					return;
				}
				//we can wait on the following until the last minute to ensure the user is actually entering a new game
				// therefore, execute in GameLoad
				/*
				ArrayList<String> tmplist = new ArrayList<String>();
				tmplist.add(this.player1);
				tmplist.add(this.player2);
				UIController.setGamePlayers(tmplist);
				*/
				UIController.printPopup("Player 2 has been authenticated!", 7.5);
				UIController.changeState("GameLoad");
				try{
					((GameLoad)UIController.grabState("GameLoad")).getGames(this.player1, this.player2);
				}catch (NullPointerException EXC){
					System.out.println("Game Logon failed to gain instance of GameLoad");
				}
				this.setupP1Logon();
				
			}else{
				UIController.printPopup("Player 1 has been authenticated!", 7.5);
				this.player1 = new String(curruser);
				this.setupP2Logon();
			}
		}

	}

	//hidden convenience method for attempting to create a new account
	private void createPlayer() {

		//declare some vars
		String curruser = this.username_fld.getText();
		String currpass = new String(this.password_fld.getPassword());
		boolean result = false;

		result = UIController.createUser(curruser, currpass);
		if (!result){
			this.showInfoNotice("The account could not be created!"
				+ "\nThe username already exists or the username/password are not in the correct format."
				+ "\n\nThe password must be from 6 to 16 characters long."
				+ "\nThe username must be from 4 to 32 characters long."
				+ "\nThe password and username must be a valid String.", "Creation Failure");
		}else{
			this.loginPlayer();
		}

	}

	//implement ActionListener
	public void actionPerformed(ActionEvent EVE) {

		//determine the caller
		Object tmpobj = EVE.getSource();
		if (tmpobj.equals(this.username_fld)){
			//check if ENTER key sent
			//System.out.println(EVE.getID());
			//login procedures
			this.loginPlayer();
		}else if (tmpobj.equals(this.password_fld)){
			//check if ENTER key sent
			//System.out.println(EVE.getID());
			//login procedures
			this.loginPlayer();
		}else if (tmpobj.equals(this.goback_btn)){
			if (this.state == GameLogon.PLAYER2_LOGON){
				setupP1Logon();
			}else{
				UIController.changeState("MainView");
			}
		}else if (tmpobj.equals(this.clear_btn)){
			this.clearFields();
		}else if (tmpobj.equals(this.login_btn)){
			//login procedures
			this.loginPlayer();
		}else if (tmpobj.equals(this.newacc_btn)){
			//creation procedures
			this.createPlayer();
		}

	}

}